package com.tmall.tmall.mapper;

import com.tmall.tmall.pojo.Shoppingcart;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ShoppingcartMapper {

    @Insert("insert into tmall.shoppingcart(user_id, product_id, quantity) VALUES (#{userId},#{productId},#{quantity})")
    void addShoppingcart(Shoppingcart shoppingCart);


    @Select("select * from tmall.shoppingcart where user_id = #{uid}")
    List<Shoppingcart> page(Integer uid);

    @Delete("delete from tmall.shoppingcart where id = #{id}")
    void deleteById(Long id);

    @Update("update tmall.shoppingcart set  quantity = #{quantity} where id = #{id}")
    void updateQuantity(Long id, Integer quantity);

    @Delete("delete from tmall.shoppingcart where user_id = #{uid} and product_id=#{pid}")
    void deleteByUidAndPid(Integer uid, Integer pid);

    @Select("select * from tmall.shoppingcart where id = #{id};")

    Shoppingcart getById(Long id);

    @Select("select * from tmall.shoppingcart where product_id = #{productId}")
    Shoppingcart getByProductId(Long productId);
}




